#pragma once
#include "ISerializer.h"
#include <libxml/xmlwriter.h>
#include <libxml/xmlreader.h>

class XmlSerializer : public ISerializer
{
public:
	XmlSerializer(char* filename);
	~XmlSerializer(void);

	void BeginSerialization();
	void EndSerialization();
	void BeginDeserialization();
	void EndDeserialization();

	void StartItem(char* name, char* type, char* version);
	void StartItem(char* name);
	void EndItem(char* name);
	
	void SerializeProperty(char* name, bool value);
	void SerializeProperty(char* name, signed char value);
	void SerializeProperty(char* name, unsigned char value);
	void SerializeProperty(char* name, signed short int value);
	void SerializeProperty(char* name, unsigned short int value);
	void SerializeProperty(char* name, signed long int value);
	void SerializeProperty(char* name, unsigned long int value);
	void SerializeProperty(char* name, float value);
	void SerializeProperty(char* name, double value);
	void SerializeProperty(char* name, long double value);
	void SerializeProperty(char* name, signed long long int value);
	void SerializeProperty(char* name, unsigned long long int value);
	void SerializeProperty(char* name, char* value);

	char* CurrentName();
	char* CurrentValue();
	char* CurrentType();
	char* CurrentVersion();
	char* ChildName(int index);
	char* ChildValue(int index);
	void MoveToChild(int index);
	void MoveToParent();

	bool CurrentValueAsBool();
	signed char CurrentValueAsSChar();
	unsigned char CurrentValueAsUChar();
	signed short int CurrentValueAsSShort();
	unsigned short int CurrentValueAsUShort();
	signed long int CurrentValueAsSLong();
	unsigned long int CurrentValueAsULong();
	float CurrentValueAsFloat();
	double CurrentValueAsDouble();
	long double CurrentValueAsLongDouble();
	signed long long CurrentValueAsSLongLong();
	unsigned long long CurrentValueAsULongLong();

	bool ChildValueAsBool(int index);
	signed char ChildValueAsSChar(int index);
	unsigned char ChildValueAsUChar(int index);
	signed short int ChildValueAsSShort(int index);
	unsigned short int ChildValueAsUShort(int index);
	signed long int ChildValueAsSLong(int index);
	unsigned long int ChildValueAsULong(int index);
	float ChildValueAsFloat(int index);
	double ChildValueAsDouble(int index);
	long double ChildValueAsLongDouble(int index);
	signed long long ChildValueAsSLongLong(int index);
	unsigned long long ChildValueAsULongLong(int index);

	AUTO_SIZE;
private:
	char* filename;
	xmlTextWriterPtr xmlWriter;
	xmlDocPtr document;
	xmlNodePtr currentNode;

	xmlNodePtr findChild(int index);
};
